package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 调用数据编辑方法的入口类型
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/10/18 14:19
 * @since v1.0
 */
@Getter
public enum UpdateDataTypeEnum {
    UPDATE(1,"enum.updateDataType.name.update"),
    COPY(2,"enum.updateDataType.name.copy"),
    LINK_ADD(3,"enum.updateDataType.name.link_add"),
    DETAIL(4,"enum.updateDataType.name.detail")
    ;

    private Integer code;
    private String name;

    UpdateDataTypeEnum(Integer code,String name) {
        this.name = name;
        this.code = code;
    }

    public boolean isCopy() {
        return Objects.equals(this.getCode(), COPY.getCode());
    }

    public boolean isUpdate() {
        return Objects.equals(this.getCode(), UPDATE.getCode());
    }

    public boolean isLinkAdd() {
        return Objects.equals(this.getCode(), LINK_ADD.getCode());
    }

    public boolean isDetail() {
        return Objects.equals(this.getCode(), DETAIL.getCode());
    }

    public boolean formatShow(Integer showType) {
        if (Objects.isNull(showType)){
            return true;
        }
        switch (this){
            case UPDATE:
            case COPY:
            case LINK_ADD:
                return ShowTypeEnum.editShow(showType);
            case DETAIL:
                return ShowTypeEnum.detailShow(showType);
            default:
                return true;
        }
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
